<template>
  <div class="home" @click="searchSelectShow = false;">
    <newHeader class="header-home" />
    <el-carousel height="500px">
      <el-carousel-item v-for="(v, i) in banner" :key="i">
        <a :href="v.pre_url" v-if="v.pre_url" target="_blank">
          <img :src="v.img_url" alt="">
        </a>
        <img :src="v.img_url" alt="" v-else>
        <!-- 以后会用 -->
        <!-- <div v-if="i === 0" class="w">
          <div class="fl">
            <div class="total">
              <div class="title">昨日每T总收益</div>
              <p>0.23233323 BTC</p>
            </div>
            <div class="symbol">=</div>
            <ul>
              <li>0.23233323 BTC</li>
              <li class="symbol">+</li>
              <li>0.23233323 BTC</li>
              <li class="symbol">+</li>
              <li>0.23233323 BTC</li>
            </ul>
          </div>
        </div> -->
      </el-carousel-item>
    </el-carousel>
    <section class="notice" v-if="notice.length">
      <ul class="w clearfix">
        <li v-for="(v,k) in notice" :key="k" class="fl text-truncate">
          <a :href="v.url" target="_blank">
            <i class="icon-gonggao iconfont"/><span v-html="v.title"/>
          </a>
        </li>
      </ul>
    </section>
    <div class="w">
      <!-- <div class="search-container">
        <input type="text" :placeholder="$t('subaccount.input_wallet_address')" v-model="searchVal" @keyup.enter="search">
        <span class="button" @click="search">{{$t('statistics.detail')}}</span>
        <span class="select-button" @click.stop="searchSelectShow = !searchSelectShow">{{ !searchSelectVal ? $t('subaccount.currency') : searchSelectVal}}
          <i class="iconfont icon-xiala" :class="{active: searchSelectShow}"></i>
        </span>
        <div @click.stop="()=>{}" class="select" v-show="searchSelectShow">
          <ul>
            <li @click="searchSelectVal = 'ETH'; searchSelectShow = false">
              <i></i>ETH</li>
            <li @click="searchSelectVal = 'DCR'; searchSelectShow = false">
              <i></i>DCR</li>
            <li @click="searchSelectVal = 'ETP'; searchSelectShow = false">
              <i></i>ETP</li>
          </ul>
        </div>
      </div> -->
      <index-table/>
      <section class="area problem">
        <div class="title">
          <!-- <p>COMMON PROBLEMS</p> -->
          <h2>— {{$t('home.problem')}} —</h2>
        </div>
        <div class="content">
          <ul>
            <li>
              <p class="ask">{{$t('home.howtoin')}}</p>
              <p class="answer">{{$t('home.info1')}}
                <a :href="preHelpHref+'/articles/360015787031'" target="_blank">{{$t('home.detail')}}>></a>{{$t('home.info2')}}
                <a :href="preHelpHref+'/articles/360015486632'" target="_blank">{{$t('home.detail')}}>></a>。</p>
            </li>
            <li>
              <p class="ask">{{$t('home.about_pay')}}</p>
              <p class="answer" v-html="$t('home.pay_info1')">
              </p>
            </li>
            <li>
              <p class="ask">{{$t('home.reasons')}}</p>
              <p class="answer" v-html="$t('home.reasons_info')">
              </p>
            </li>
          </ul>
        </div>
      </section>
      <section class="area advantages">
        <div class="title">
          <!-- <p>OUR ADVANTAGES</p> -->
          <h2>— {{$t('home.advantages')}} —</h2>
        </div>
        <div class="content">
          <div class="row">
            <div class="item">
              <img :src="require('@/assets/images/home/advantage_01.png')" alt="">
              <h3>{{$t('home.save')}}</h3>
              <p>
                FINANCIAL SECURITY<br>TIMELY SETTLEMENT
              </p>
              <h4 v-if="language === 'zh'">{{$t('home.timely')}}</h4>
            </div>
            <div class="item">
              <img :src="require('@/assets/images/home/advantage_02.png')" alt="">
              <h3>{{$t('home.exclusive')}}</h3>
              <p>
                PROFESSIONAL CUSTOMER SERVICE<br>QUALITY SERVICE
              </p>
              <h4 v-if="language === 'zh'">{{$t('home.quality')}}</h4>
            </div>
            <div class="item">
              <img :src="require('@/assets/images/home/advantage_03.png')" alt="">
              <h3>{{$t('home.intelligent')}}</h3>
              <p>
                INTELLIGENT MONITORING<br>STABLE AND SAFE
              </p>
              <h4 v-if="language === 'zh'">{{$t('home.stable')}}</h4>
            </div>
          </div>
          <div class="row">
            <i></i>
            {{$t('home.info')}}
          </div>
        </div>
      </section>
      <section class="app">
        <div class="introduction">
          <div class="title">
            <p>DPOOL APP</p>
            <h2>{{$t('home.info3')}}</h2>
          </div>
          <div class="content" v-html="$t('home.info4')">

          </div>
        </div>
        <div class="QR-code">
          <h3>{{$t('home.down')}}</h3>
          <img :src="require('@/assets/images/QR-code/download-app.png')" alt="">
        </div>
      </section>
    </div>
    <div class="back_top" @click="backTop">
      <i class="iconfont icon-weibiaoti-"></i>
    </div>
    <newFooter class="footer-home" />
  </div>
</template>
<script>
import newHeader from '@/components/Header';
import newFooter from '@/components/Footer';
import { getNoticeList, banner } from '@/api';
import { mapGetters } from 'vuex';
import indexTable from './table/index';

export default {
  name: 'index',
  components: {
    newHeader,
    newFooter,
    indexTable,
  },
  data() {
    return {
      window,
      // banner: [],
      // notice: [],
      bannerObj: {
        cn: [],
        en: [],
      },
      noticeObj: {
        cn: [],
        en: [],
      },
      // searchVal: '',
      // search_disabled: false,
      // searchSelectVal: '',
      // searchSelectShow: false,
    };
  },
  computed: {
    ...mapGetters(['language']),
    preHelpHref() {
      return `https://support.dpool.top/hc/${this.language === 'zh' ? 'zh-cn' : 'en-us'}`;
    },
    banner() {
      if (this.language === 'zh') {
        return this.bannerObj.cn;
      }
      return this.bannerObj[this.language];
    },
    notice() {
      if (this.language === 'zh') {
        return this.noticeObj.cn;
      }
      return this.noticeObj[this.language];
    },
  },
  created() {
    this.getBanner();
    this.getNotice();
  },
  mounted() {
    const oldMethod = window.onscroll;
    if (typeof oldMethod === 'function') {
      window.onscroll = () => {
        oldMethod.call(window);
        this.showBackTop();
      };
    } else {
      window.onscroll = () => {
        this.showBackTop();
      };
    }
  },
  methods: {
    getBanner() {
      ['cn', 'en'].forEach((languageType) => {
        banner({ type: 'pc', language_type: languageType }).then((res) => {
          if (res.data.status === 1 && Array.isArray(res.data.data)) {
            this.bannerObj[languageType] = res.data.data;
          }
        });
      });
    },
    // search() {
    //   if (!this.searchSelectVal) {
    //     this.$message({
    //       message: this.$t('api.6051'),
    //       type: 'warning',
    //     });
    //     return;
    //   }
    //   if (!this.searchVal) {
    //     this.$message({
    //       message: this.$t('subaccount.input_wallet_address'),
    //       type: 'warning',
    //     });
    //     return;
    //   }
    //   if (this.search_disabled) {
    //     return;
    //   }
    //   this.search_disabled = true;
    //   const coinType = this.searchSelectVal.toLowerCase();
    //   InSearchInfo({
    //     coin_type: coinType,
    //     address: this.searchVal,
    //   }).then((res) => {
    //     if (res.data.status === 1) {
    //       this.$router.push(`minersearch?coin_type=${coinType}&address=${this.searchVal}`);
    //     } else {
    //       this.$message({
    //         message: this.$t('home.wallet_address'),
    //         type: 'warning',
    //       });
    //     }
    //     this.search_disabled = false;
    //   }).catch(() => {
    //     this.search_disabled = false;
    //   });
    // },
    backTop() {
      window.scrollTo(0, 0);
    },
    showBackTop() {
      const currentScroll = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
      const backTop = document.querySelector('.back_top');
      if (backTop) {
        if (currentScroll > 1000) {
          document.querySelector('.back_top').style.display = 'block';
        } else {
          document.querySelector('.back_top').style.display = 'none';
        }
      }
    },
    getNotice() {
      ['cn', 'en'].forEach((languageType) => {
        getNoticeList({ language_type: languageType }).then((res) => {
          if (res.data.status === 1 && res.data.data) {
            this.noticeObj[languageType] = res.data.data.slice(0, 3);
          }
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.home {
  background-color: #2a2a3a;
  .el-carousel {
    /deep/ .el-carousel__arrow {
      font-size: 44px;
      background-color: transparent;
      &.el-carousel__arrow--left {
        left: calc(50% - 588px);
      }
      &.el-carousel__arrow--right {
        right: calc(50% - 588px);
      }
      i {
        color: rgba(255, 255, 255, 0.1);
        &:hover {
          color: rgba(255, 255, 255, 0.3);
        }
      }
    }
    .el-carousel__item {
      > a {
        width: 100%;
        height: 100%;
        display: block;
      }
      > img,
      > a > img {
        height: 500px;
        min-width: 100%;
        position: absolute;
        left: 50%;
        top: 0;
        transform: translateX(-50%);
        z-index: -1;
        max-width: none;
      }
      > .w {
        height: 100%;
        line-height: 30px;
        color: #1dd3ad;
        font-size: 24px;
        .fl {
          margin: 177px 77px;
          width: 520px;
          height: 170px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .title {
            font-size: 18px;
            text-align: center;
          }
          .symbol {
            color: #fff;
            font-size: 35px;
            text-align: center;
            height: 40px;
            line-height: 40px;
          }
        }
      }
    }
    /deep/ .el-carousel__indicators {
      margin-bottom: 70px;
      .el-carousel__indicator {
        .el-carousel__button {
          opacity: 1;
          background-color: #1dd3ad;
        }
        &.is-active .el-carousel__button {
          background-color: #fff;
        }
      }
    }
  }
  .notice {
    height: 60px;
    line-height: 60px;
    background-color: rgba(0, 0, 0, 0.3);
    margin-top: -60px;
    z-index: 2;
    position: relative;
    ul {
      display: flex;
      justify-content: space-between;
      li {
        flex: 1;
        flex-grow: 1;
        font-size: 14px;
        a {
          color: #fff;
          &:hover {
            color: #1dd3ad;
          }
          i {
            font-size: 20px;
            margin-right: 10px;
            vertical-align: middle;
          }
        }
      }
    }
  }
  // .search-container {
  //   width: 770px;
  //   height: 60px;
  //   background-color: #ffffff;
  //   border: solid 2px #1dd3ad;
  //   border-radius: 30px;
  //   margin: 50px auto 0;
  //   font-size: 18px;
  //   display: flex;
  //   justify-content: space-between;
  //   position: relative;
  //   .button {
  //     display: inline-block;
  //     background-color: #1dd3ad;
  //     text-align: center;
  //     cursor: pointer;
  //     border-radius: 28px;
  //     line-height: 56px;
  //     width: 170px;
  //     color: #fff;
  //     &:hover {
  //       background-color: #4adcbd;
  //     }
  //   }
  //   input {
  //     border: none;
  //     outline: none;
  //     padding: 0 33px 0 110px;
  //     width: 596px;
  //     text-align: left;
  //     border-top-left-radius: 28px;
  //     border-bottom-left-radius: 28px;
  //   }
  //   .select-button {
  //     color: #1dd3ad;
  //     font-size: 18px;
  //     position: absolute;
  //     height: 56px;
  //     line-height: 56px;
  //     top: 0;
  //     left: 30px;
  //     cursor: pointer;
  //     i {
  //       transition: transform 0.3s;
  //       display: inline-block;
  //       &.active {
  //         transform: rotate(180deg);
  //       }
  //     }
  //   }
  //   .select {
  //     width: 700px;
  //     height: 60px;
  //     line-height: 60px;
  //     background-color: #ffffff;
  //     border-radius: 0px 0px 3px 3px;
  //     position: absolute;
  //     top: 70px;
  //     left: 35px;
  //     padding: 0 42px;
  //     li {
  //       display: inline-block;
  //       margin-right: 100px;
  //       cursor: pointer;
  //       &:hover {
  //         color: #1dd3ad;
  //       }
  //       &:first-of-type i {
  //         background: url(../../assets/images/home/icon_eth.png) no-repeat;
  //       }
  //       &:nth-of-type(2) i {
  //         background: url(../../assets/images/home/icon_dcr.png) no-repeat;
  //       }
  //       &:nth-of-type(3) i {
  //         background: url(../../assets/images/home/icon_etp.png) no-repeat;
  //       }
  //       i {
  //         width: 24px;
  //         height: 24px;
  //         display: inline-block;
  //         vertical-align: sub;
  //         margin-right: 10px;
  //       }
  //     }
  //   }
  // }
  .area {
    margin-top: 70px;
    .title {
      text-align: center;
      margin-bottom: 40px;
      p {
        font-size: 18px;
        color: #1dd3ad;
      }
      h2 {
        font-size: 24px;
        color: #0095ff;
      }
    }
    &.problem {
      .content {
        line-height: 36px;
        color: #fff;
        p {
          padding-left: 55px;
          &.ask {
            background: url(../../assets/images/home/icon_q.png) left top
              no-repeat;
            background-size: 36px 36px;
            margin-bottom: 20px;
            font-size: 18px;
          }
          &.answer {
            background: url(../../assets/images/home/icon_a.png) left top
              no-repeat;
            background-size: 36px 36px;
            margin-bottom: 50px;
            font-size: 14px;
            a {
              color: #0095ff;
              // font-size: 18px;
            }
          }
        }
      }
    }
    &.advantages {
      .row {
        &:first-of-type {
          display: flex;
          justify-content: space-around;
          .item {
            text-align: center;
            width: 350px;
            &:nth-of-type(2) {
              width: 380px;
            }
            img {
              margin-bottom: 12px;
            }
            h3 {
              color: #03cfa7;
              font-size: 24px;
              line-height: 53px;
            }
            p {
              font-size: 18px;
              color: #fff;
              line-height: 24px;
            }
            h4 {
              font-size: 18px;
              color: #03cfa7;
              line-height: 56px;
            }
          }
        }
        &:last-of-type {
          width: 710px;
          position: relative;
          padding: 66px 75px;
          font-size: 18px;
          color: #fff;
          text-align: center;
          margin: 25px auto 0;
          i {
            width: 53px;
            height: 1px;
            background-color: #03cfa7;
            position: absolute;
            top: 40px;
            left: 50%;
            transform: translateX(-50%);
          }
          &::before {
            content: " ";
            position: absolute;
            top: 0;
            left: 0;
            background: url(../../assets/images/home/description_top.png)
              no-repeat;
            background-size: 135px 135px;
            width: 135px;
            height: 135px;
          }
          &::after {
            content: " ";
            position: absolute;
            right: 0;
            bottom: 0;
            background: url(../../assets/images/home/description_bottom.png)
              no-repeat;
            background-size: 135px 135px;
            width: 135px;
            height: 135px;
          }
        }
      }
    }
  }
  .app {
    width: 1160px;
    height: 811px;
    background: url(../../assets/images/home/app_bg.png) no-repeat;
    background-size: 1160px 811px;
    position: relative;
    .introduction {
      margin-top: 73px;
      width: 480px;
      text-align: center;
      .title {
        font-size: 24px;
        p {
          color: #03cfa7;
        }
        h2 {
          color: #0095ff;
          white-space: nowrap;
        }
      }
      .content {
        font-size: 18px;
        color: #fff;
      }
    }
    .QR-code {
      width: 170px;
      color: #03cfa7;
      font-size: 24px;
      text-align: center;
      position: absolute;
      right: 26px;
      bottom: 150px;
      img {
        width: 170px;
      }
    }
  }
  .back_top {
    position: fixed;
    bottom: 20%;
    right: 10%;
    cursor: pointer;
    display: none;
    z-index: 1;
    i {
      font-size: 50px;
      color: rgba(0, 0, 0, 0.5);
    }
    &:hover i {
      color: #1dd3ad;
    }
  }
}
</style>

